<script>
export default {
  /** 复制选中关键词按钮*/
  name: "copyKeyWordBtn",
  props: {
    selectRow: {
      type: Array,
      required: true
    },
    show: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {};
  },
  methods: {
    copy() {
      let _ = this;
      const formattedText = _.selectRow.map(i => i.name).join("\n");
      _.$copyText(formattedText).then(() => {
        _.$message.success("已成功复制到剪贴板");
      }).catch((error) => {
          _.$message.warning("复制到剪贴板时出错: " + error);
      });
    }
  }
};
</script>

<template>
  <div style="display: inline">
    <el-button
      v-if="show"
      size="mini"
      type="primary"
      :disabled="selectRow.length === 0"
      @click="copy"
    >
      复制选中关键词
    </el-button>
  </div>
</template>

<style scoped>

</style>